package com.example.share_doc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.share_doc.entity.Message;
import com.example.share_doc.mapper.MessageMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@AllArgsConstructor
public class MessageService {

    private MessageMapper messageMapper;

    public Message messageLatest() {
        QueryWrapper<Message> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(Message::getUpdateTime).last("limit 1");
        return messageMapper.selectOne(queryWrapper);
    }

    public void updateMessage(Message message) {
        messageMapper.insertOrUpdate(message);
    }

    public void deleteMessageList(List<String> messageIdList) {
        messageMapper.deleteByIds(messageIdList);
    }
}
